package org.uugu.iws.util;

import org.springframework.core.io.support.ResourcePropertySource;

import java.io.IOException;

/**
 * 文件操作工具类
 *
 * @author ChenZhiguo Created on 2014/11/4.
 */
public class FileUtil {

    private static String PROPERTIES_PATH = "classpath:appconfig.properties";


    /**
     * 读properties文件，得到文件中内容
     * @param key  需要读取的key
     * @return
     * @throws IOException
     */
    public static String readValueForProperties(String key){
        ResourcePropertySource propertySource2 = null;
        try {
            propertySource2 = new ResourcePropertySource("resource", PROPERTIES_PATH);
        } catch (IOException e) {
            return  "";
        }
        Object pValue = propertySource2.getProperty(key);
        if(pValue != null)
            return pValue.toString();
        return "";
    }
}